<script>
$(function(){
    $('#menu_id').attr('value',INPUT_GET.menu_id);
    $('td[edit]').dblclick(function(){
        var val = $(this).html();
        var field = $(this).attr('field');
        var wparam = $(this).parents().attr('wparam');
        var uuid = AUKEY+field+wparam;
        $(this).html("<input id='"+uuid+"' style='width:auto;' value='"+val+"' />");
        $('#'+uuid).focus().live('blur',function(){
            var now_val = $(this).val();
            var td_obj = $(this).parents('td');
            $.post(location.href,{val:now_val,field:field,wparam:wparam,type:'edit'},function(data){
                dialogMessage(data.message,'green');
                td_obj.html(data.state == 1 ? now_val : val);
            },'json');
        });
    });
    // 删除
    $('img[del]').click(function (){
        var node_id = $(this).attr('del');
        $.post(location.href,{node_id:node_id,type:'delete'},function(data){
            dialogMessage('操作成功','green');
            $('tr[wparam='+node_id+']').remove();
        },'json');
    });
    // 修改可见状态
    $('img[yesno]').click(function(){
        var obj = $(this);
        $.post(location.href,{node_id:$(this).attr('yesno'),type:'yesno'},function(data){
            if (data.state <= 0)
            {
                alert(data.message);
                return false;
            }
            dialogMessage(data.message,'green');
            obj.attr('src',data.extra);
        },'json');
    });
    // 快速添加
    $('#fast_add').submit(function(){
        var data = $(this).serialize()+'&app=<?php echo APP; ?>&mod=<?php echo MOD; ?>';
        $.post('system.php',data,function(data){
            if (data.state <= 0)
            {
                alert(data.message);
                return false;
            }
            dialogMessage(data.message,'green');
            location.href = location.href;
        },'json');
        return false;
    });
    $('.span_now').click(function(){
        var edv = $('.edit_div');
        edv.css('display',edv.css('display') == 'none' ? 'block' : 'none');
    });
});
</script>
<div class="search">
    <form id='search'>
        <span><select name="menu_id" id="menu_id" class="select1"><option>请选择菜单分组</option><?php foreach($this->menus as $menu): ?><option value="<?php echo $menu['menu_id']; ?>"><?php echo $menu['name']; ?></option><?php endforeach; ?></select></span>
        <span><input name="" type="submit" value="搜索" /><?php echo showhide(array('app'=>'perm','mod'=>'node')); ?></span>
    </form>
</div>
<div class="line_1"></div>
<table width="100%" cellpadding="0" cellspacing="0" border="0" class="table1">
       <tr>
            <th class="th0">编号</th>
            <th class="th1">节点名称</th>
            <th class="th1">归属菜单名称</th>
            <th class="th1">APP参数</th>
            <th class="th1">MOD参数</th>
            <th class="th0">是否可见</th>
            <th class="th0">排序</th>
            <th class="th0">操作</a>
       </tr>
       <?php foreach($this->nodes as $node): ?> 
       <tr wparam='<?php echo $node['node_id']; ?>'>
            <td><?php echo $node['node_id']; ?></td>
            <td edit field='name'><?php echo $node['name']; ?></td>
            <td><?php echo $node['menu_name'] ? $node['menu_name'].'('.$node['menu_id'].')' : '<span style="color:red">未分配</span>'; ?></td>
            <td edit field='app_val'><?php echo $node['app_val']; ?></td>
            <td edit field='mod_val'><?php echo $node['mod_val']; ?></td>
            <td><?php echo yesno(!$node['hidden'],'yesno="'.$node['node_id'].'"'); ?></td>
            <td edit field='sort'><?php echo $node['sort']; ?></td>
            <td><?php echo opt('trash','javascript:;','del="'.$node['node_id'].'"'); ?></td>
       </tr>
       <?php endforeach; ?>
</table>
<div class="page_num">
     <div class="fr">
        <span>提示：双击编辑，鼠标点击页面其他处提交修改</span>
     </div>
</div>
<div class="line_1"></div>
<div class="edit_tab tab"><div class="bg1"><div class="bg2"><span class="span_now">快速添加</span></div></div></div>
<div class="edit_div" style="display:none">
    <div class="line_1"></div><form id="fast_add" onSubmit="return false;">
    <div class="form_div1">
        <span class="span1">节点名称</span>
        <span><input type="text" name="name" /></span>
    </div>
    <div class="form_div1">
        <span class="span1">APP参数</span>
        <span><input type="text" name="app_val"/></span>
    </div>
    <div class="form_div1">
        <span class="span1">MOD参数</span>
        <span><input type="text" name="mod_val"/></span>
    </div>
    <div class="form_div1">
        <span class="span1">是否可见</span>
        <span>
            <select name="hidden" style="width:60px;">
                <option value="0">是</option>
                <option value="1">否</option>
            </select>
        </span>
    </div>
    <div class="form_div1"><span class="span1"></span><span><?php echo showhide('type','add'); ?><input type="submit" value="提交" class="btn1"/><input type="reset" class="btn1"/></span></div></form>
</div>